﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataAccess.AppConfig;
using FOModels.AppConfig;
using System.Data;
using System.Net;
namespace Bussiness.AppConfig
{
    public class AppConfigBLL
    {
        private AppConfigDAL dal;
        public AppConfigBLL()
        {
            dal = new AppConfigDAL();
        }

        public AppConfigModels getAppConfig(int AppConfigID, int langid)
        {
            AppConfigModels fur = new AppConfigModels();
            DataTable tb = dal.getAppConfig(AppConfigID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AppConfigModels();
                    fur.AppConfigID = int.Parse(row["AppConfigID"].ToString());
                    fur.SiteTitle = row["SiteTitle"].ToString();
                    fur.CallCenter = row["CallCenter"].ToString();
                    fur.MailServer = row["MailServer"].ToString();
                    fur.MailUser = row["MailUser"].ToString();
                    fur.MailPassword = row["MailPassword"].ToString();
                    fur.MailPort = row["MailPort"].ToString();
                    fur.IntroSite = WebUtility.HtmlDecode(row["IntroSite"].ToString());
                    fur.Contact = WebUtility.HtmlDecode(row["Contact"].ToString());
                    fur.Term = WebUtility.HtmlDecode(row["Term"].ToString());
                    fur.AboutUs = WebUtility.HtmlDecode(row["AboutUs"].ToString());
                }
                return fur;
            }
            else
            {
                return null;
            }

        }
        public int UpdateAppConfig(AppConfigModels models, int langid)
        {
            if (dal.UpdateAppConfig(models) > 0 && dal.UpdateAppConfigLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }

    }
}
